package entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.TreeSet;

@SuppressWarnings("unused")
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
    private String username;
    private String password;
    private TreeSet<String> images;
    private TreeSet<Record> records;
    private String avatar;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public void addRecord(Record record) {
        // 检查 records 是否为 null，如果是则初始化
        if (records == null) {
            records = new TreeSet<>(Record::compareTo);
        }
        records.add(record);
    }

    // 获取 records 的安全方法
    public TreeSet<Record> getRecords() {
        if (records == null) {
            records = new TreeSet<>();
        }
        return new TreeSet<>(records);
    }
}